package com.yc.txx.mapper;

import com.yc.txx.entity.Lease;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 廖老师
 * @since 2023-04-30
 */
public interface LeaseMapper extends BaseMapper<Lease> {
    @Override
    @Insert("insert into lease values(default,#{cid},#{uid}," +
            "#{beginday},#{days},#{money},#{state},null)")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int insert(Lease entity);


    @Select("select * from lease where cid = #{cid} and beginday > now()")
    List<Lease> selectUnfinishByCid(int cid);


    @Results({
            @Result(id = true,column = "id",property = "id"),
              @Result(column ="cid",property = "car",
                    one = @One(select = "com.yc.txx.mapper.CarMapper.selectById1"))
    })
    @Select("select * from lease where uid = #{uid}")
    List<Lease> selectByUid(int uid);

    @Update("update lease set state = #{state} where id = #{id}")
    void updateState(@Param("state") String state,@Param("id") String id);
}
